<template>
  <div class="axios">
    <h1>axios发请求示例</h1>
    <p>{{$store.state.age}}</p>
    <button @click="getData">发请求</button>
    <p class="list">商品列表</p>
    <ul>
      <li v-for="(item, index) in goodsList" :key="index">
        <img :src="item.image_url" :alt="item.goods_name" width="60">
        <span>{{item.goods_name}}</span>
        <span>￥{{item.goods_price}}</span>
      </li>
    </ul>
  </div>
</template>
<script>
export default {
  data() {
    return {
      goodsList: []
    }
  },
  created() {
    this.getData()
  },
  methods: {
    getData() {
      this.$http('/goods/shopwindow')
      .then(res => {
        // console.log(res);
        // 根据后端的数据，赋值给数组，回显
        this.goodsList = res.result.data
      })
      .catch(err => {
        console.log(error);
      })
    }
  }
}
</script>
<style lang="stylus">
  color1=red
  color2=blue
  fsize = 40px
  span
    font-size 20px
    color color1
  .axios .list 
    color color2
    font-size fsize
</style>